package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author LYQ
 * @since 2024-06-25
 */
@Api(tags = "客户端 - 互动问答相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("questions")
public class InteractionQuestionController {
    private final IInteractionQuestionService questionService;

    /**
     * 分页查询提问数据
     *
     * @param pageQuery
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("客户端 - 分页查询提问数据")
    public PageDTO<QuestionVO> queryPage(QuestionPageQuery pageQuery) {
        return questionService.queryPage(pageQuery);
    }

    /**
     * 新增提问
     *
     * @param questionDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增提问")
    public void insertQuestion(@RequestBody QuestionFormDTO questionDTO) {
        questionService.insertQuestion(questionDTO);
    }

    /**
     * 用户端 - 根据id查询问题详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("客户端 - 根据id查询问题详情")
    public QuestionVO queryQuestionById(@PathVariable Long id) {
        return questionService.queryQuestionById(id);
    }

    /**
     * 用户端 - 根据id修改问题
     *
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("客户端 - 根据id修改问题")
    public void updateQuestionById(@PathVariable Long id, @RequestBody QuestionFormDTO questionDTO) {
        questionService.updateQuestionById(id, questionDTO);
    }


    /**
     * 用户端 - 根据id删除问题
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("客户端 - 根据id删除问题")
    public void deleteQuestionById(@PathVariable Long id) {
        questionService.deleteQuestionById(id);
    }
}
